﻿using DataEntity.Entities;
using IService;
using Microsoft.EntityFrameworkCore;
using Model.DynamicDTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Service
{

    public class DynamicService: IDynamicService
    {
    #region 构造函数依赖注入

    private readonly DbContext _dbContext;
    public DynamicService(DbContext dbContext)
    {
        _dbContext = dbContext;
    }
    #endregion
        /// <summary>
        /// 添加动态板块
        /// </summary>
        /// <param name="regInput"></param>
        /// <returns></returns>
        public bool AddDynamic(DynamicInput regInput)
        {
            var IDynamic = _dbContext.Set<Tmessage>().FirstOrDefault();
            if (IDynamic != null)
            {
                return false;
            }
            else
            {
                _dbContext.Add(new Tmessage
                {
                    MessageTitle = regInput.MessageTitle,
                    MessageContent=regInput.MessageContent,
                    GuestName= regInput.GuestName,
                    MessageTime= regInput.MessageTime,
                    MessageKind= regInput.MessageKind,
                    IsPase= regInput.IsPase,
                    ClickNumber= regInput.ClickNumber,
                    IsTop= regInput.IsTop,
                    Reply= regInput.Reply,
                    LastCommentTime= regInput.LastCommentTime,
                });
                int results = _dbContext.SaveChanges();
                if (results > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}
